import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class C {

    BufferedReader fin;
    PrintWriter fout;

    void openFiles() throws IOException {
        fin = new BufferedReader(new FileReader("C.in"));
        fout = new PrintWriter(new BufferedWriter(new FileWriter("C.out")));
    }

    void closeFiles() throws IOException {
        fin.close();
        fout.close();
    }

    String spec = "welcome to code jam";
    int[][] d;
    int N;
    
    void input() throws IOException {
    	N = Integer.parseInt(fin.readLine());
    }
    
    int solve(String text)
    {
    	d = new int[spec.length()][text.length()];

    	//init
    	for (int i = 0; i < text.length(); i++)
    		if (text.charAt(i) == 'w') d[0][i] = 1;
    		else d[0][i] = 0;
    	
    	for (int k = 1; k < spec.length(); k++)
    		for (int i = k; i < text.length(); i++)
    			if (text.charAt(i) == spec.charAt(k))
    			{
    				for (int j = k-1; j < i; j++)
    					if (text.charAt(j) == spec.charAt(k-1))
    					{
    						d[k][i] = (d[k][i] + d[k-1][j]) % 10000;
    					}
    			}
    	
    	int res = 0;
    	for (int i = 0; i < text.length(); i++)	res += d[spec.length()-1][i];
    	return res % 10000;
    }
    
    void process() throws IOException
    {
    	for (int i = 1; i <= N; i++)
    	{
    		String s = fin.readLine();
    		String res = Integer.valueOf(solve(s)).toString();
    		while (res.length() < 4) res = "0" + res;
    		fout.println("Case #" + i + ": " + res);
    	}
    }
    
    void output() {
    
    }
    
    public static void main(String[] args) throws IOException {
        C myProgram = new C();

        myProgram.openFiles();
        myProgram.input();
        myProgram.process();
        myProgram.output();
        myProgram.closeFiles();
    }

}
